 <template>
  <div>
      <el-main>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-form-item label="意见反馈:">
                <el-input type="textarea" v-model="form.feedback"  placeholder="小柚智汇的每一个进步都离不开您宝贵的意见和建议。"></el-input>
            </el-form-item>
        </el-form>
      </el-main>
      <span>相关图片:</span>
      <el-upload
        action="#"
        :http-request="uploadImg"
        list-type="picture-card"
        :on-preview="handlePictureCardPreview"
        :on-remove="handleRemove">
        <i class="el-icon-plus"></i>
      </el-upload>
     <el-dialog :visible.sync="dialogVisible">
        <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>
    <el-button class="submit" @click="submitForm('form')">提交</el-button>
  </div>
</template>

<script>
import { feedbackmessage, updatImg } from "@/utils/api/feedback.js"
export default {
  name: 'feedback',
  props: {},
  components: {
  },
  data () {
    return {
      form: {
        feedback: '',
        pic: []
      },
      rules: {
        feedback: [
          {
            required: true,
            trigger: 'blur',
            message: '反馈内容不能为空'
          }
        ]
      },
      dialogImageUrl: '',
      dialogVisible: false
    }
  },
  methods: {
    handleRemove (file, fileList) {
      console.log(file, fileList);
    },
    handlePictureCardPreview (file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    submitForm (formName) {
      console.log(this.form);
      console.log(this.$refs[formName]);
      this.$refs[formName].validate(isPass => {
        if (isPass) {
          console.log('1231');
          this.feedback()
        } else {
          return false
        }
        // 刷新表单
        this.$nextTick(() => {
          this.$refs.form.resetFields()
        })
      })
    },
    feedback () {
      feedbackmessage(this.form)
        .then(res => {
          console.log('res:' + res);
          if (res.data.code === 200) {
          // 成功
            this.$notify({
              title: '成功',
              message: '提交成功',
              type: 'success'
            })
          } else {
            this.$notify.error({
              title: '失败',
              message: '提交失败！请重试'
            })
          }
        })
    }
  },
  // 自定义的图片提交事件
  uploadImg (f, data) {
    console.log(f);
    const formdata = new FormData()
    formdata.append('pic', f)
    // this.loadingtext = true
    // this.cropperData.iconUrl = data
    // this.showCropper = false
    // this.formate = formdata
    updatImg(formdata).then(res => {
      console.log("res:" + res);
    })
  },
}
</script>

<style scoped lang="less">
/deep/.el-textarea__inner{
    margin-top: 25px;
    height: 250px;
    width: 330px;
    text-indent: 2rem;
}
/deep/.el-upload-list--picture-card {
    margin-left: 90px;
}
span{
    margin-left: 13px;
    color: rgb(96,98,102);
}
.submit{
    margin-left: 200px;
    margin-top: 20px;
}
/deep/.el-button:focus, .el-button:hover{
  background-color: rgb(252,223,139);
  color: rgb(56, 55, 55);
  border: none;
}

</style>
